package com.controller.lzj;


import com.bean.lzj.Material;
import com.bean.lzj.Result;
import com.bean.lzj.TruckSpace;
import com.dao.lzj.CarDao;
import com.dao.lzj.MaterielDao;
import com.dao.lzj.TruckSpaceDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.List;

/**
 * 处理物料信息
 */
@Controller

@ResponseBody
@RequestMapping("/LzjPage/")
public class MaterielController {
    /**
     * 物料
     */
    @RequestMapping(value = "getwlxx",method = RequestMethod.GET)
    @ResponseBody
    public List<Material> getcarl() throws SQLException {
        List<Material> wl = MaterielDao.getcarl();
        return wl;
    }

    /**
     * 综合查询物料信息
     * @param cxwlmc
     * @param cxwlcd
     * @return
     * @throws SQLException
     */
    @RequestMapping("wldzhcx")
    @ResponseBody

    public List<Material> wlzhxx(String cxwlmc,String cxwlcd) throws SQLException {

        List<Material> wl = MaterielDao.getwlzhxx(cxwlmc, cxwlcd);
        return wl;
    }

    /**
     * 添加物料信息
     * @param wlmc 物料名称
     * @param wlcd 物料产地
     * @param wlkc 物料库存
     * @param wljg 物料价格
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "tianjiawl",method = RequestMethod.POST)
    @ResponseBody

    public Result tianjiacl(String wlmc, String wlcd, int wlkc, int wljg ) throws SQLException {

        boolean result = MaterielDao.tianjiawl(wlmc,wlcd,wlkc,wljg);
        Result rs = new Result();
        rs.setOk(result);
        return rs;
    }

    @RequestMapping("deletewl")
    @ResponseBody
    public Result deleteClxxById(int mid) throws SQLException {
        boolean result = MaterielDao.deleteWlById(mid);
        Result rs = new Result();
        rs.setOk(result);
        return rs;
    }

    /**
     * 批量删除
     * @param fxk
     * @return
     */
    @RequestMapping("deleteinbatcheswl")
    @ResponseBody
    public Result deleteinbatchesById(int fxk) throws SQLException {
        boolean result = MaterielDao.deleteinbatchesById(fxk);
        Result rs = new Result();
        rs.setOk(result);
        return rs;
    }

    /**
     * 修改物料信息
     * @param mid
     * @param xgwlmc
     * @param xgwlcd
     * @param xgwlkc
     * @param xgwljg
     * @return
     */
    @RequestMapping("xiugaiwuliuxinxi")
    @ResponseBody

    public Result getxiugaiwuliao( int mid,String xgwlmc, String xgwlcd, int xgwlkc,int xgwljg) {
        System.out.println("修改xinxi");
        boolean result = MaterielDao.getxiugaiwuliao(mid, xgwlmc, xgwlcd, xgwlkc, xgwljg);
        Result rs = new Result();
        rs.setOk(result);
        return rs;


    }
    /**
     * 修改前先发ajax请求读要修改的数据
     */
    @RequestMapping("xiugaiwuliuchaxun")
    @ResponseBody

    public List<Material> wlxg(int mid) throws SQLException {

        List<Material> wl = MaterielDao.getwlxg(mid);
        return wl;
    }
}
